//
//  SQBDetailViewController.m
//  SP2P
//
//  Created by 吴建东 on 16/6/2.
//  Copyright © 2016年 EIMS. All rights reserved.
//

#import "SQBDetailViewController.h"
#import "CheckAdvantageViewController.h"
#import "ProductDetailView.h"
#import "InvestmentBriefView.h"
#import "TurnOutViewController.h"
#import "TransferredViewController.h"
#import "AddBankCardViewController.h"
#import "CommonWebViewController.h"
#import "ProductDetailViewController.h"
#define kButtonNum 3
@interface SQBDetailViewController ()<UITableViewDelegate,UITableViewDataSource,HTTPClientDelegate,ProductDetailViewDelegate,InvestmentBriefViewDelegate,UIAlertViewDelegate>
{
    UILabel *_rateLabel;
    UILabel *_yesProfitLabel;
    UILabel *_totalProfitLabel;
    UILabel *_totalAmountLabel;
    ClickButton *_transInButton;
    ClickButton *_transOutButton;
    
    UIButton *_productDetailButton;
    UIButton *_propertyDirectionButton;
    UIButton *_securityWayButton;
    UIView *_buttonView;
    UIView *_buttonLineView;
    
    ProductDetailView   *_productDetail;
    InvestmentBriefView *_briefView;
    
    BOOL _isTop;
}
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
//@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIScrollView *briefScrollView;
@property (nonatomic, strong) UIScrollView *detailScrollView;
@property (strong, nonatomic) IBOutlet UIView *checkDetailView;

@property (nonatomic, strong) NetWorkClient *requestClient;
@property (nonatomic, assign) NSInteger     requestType;
@property (nonatomic, assign) BOOL          isLoading;
@property (nonatomic, strong) CommonWebViewController *webView;

@end

@implementation SQBDetailViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//    [self initNavBarTitle:@"随取宝" andLeftItemName:@"返回" andRightItemName:@"查看优势"];
//    [self setNavBarBackgroundColor:[UIColor clearColor] andStatusBar:UIStatusBarStyleLightContent];
//    return;
//
      // 设置滚动视图背景做为导航的颜色
        self.scrollView.backgroundColor = KColor;
        [self initNavBarTitle:@"随取宝" andLeftItemName:@"返回" andRightItemName:@"项目详情"];
        [self setNavBarBackgroundColor:[UIColor clearColor] andStatusBar:UIStatusBarStyleLightContent];
        [self initData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self resetNavigationBar];
    
    if (_requestClient != nil) {
        [_requestClient cancel];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   
    [self initView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sqbBalanceChange) name:@"sqbBalanceChange" object:nil];
    
}

- (void)sqbBalanceChange {
    [self requestData];
}

#pragma mark - delegate
- (void)transButtonClick {
    [self transInButtonClick];
}

#pragma mark - Action
- (void)transOutButtonClick {
    if (AppDelegateInstance.userInfo == nil) {
        [ReLogin goLogin:self];
        return;
    }
    if (AppDelegateInstance.userInfo.realName.length <= 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"您尚未进行实名认证" message:@"是否前去实名认证？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alert.tag = 7;
        [alert show];
        return;
    }
    
    if (AppDelegateInstance.userInfo.hasBindCard == NO) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"您尚未完成实名认证信息" message:@"是否前去完善实名认证信息？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alertView.tag = 14;
        [alertView show];
        return;
    }
    
    TurnOutViewController *turnOut = [[TurnOutViewController alloc] initWithNibName:@"TurnOutViewController" bundle:nil];
    turnOut.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:turnOut animated:YES];
}

- (void)transInButtonClick {
    if (AppDelegateInstance.userInfo == nil) {
        [ReLogin goLogin:self];
        return;
    }
//    if (AppDelegateInstance.userInfo.realName.length <= 0) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"您尚未进行实名认证" message:@"是否前去实名认证？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//        alert.tag = 7;
//        [alert show];
//        return;
//    }
//    if (AppDelegateInstance.userInfo.hasBindCard == NO) {
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"您尚未完成实名认证信息" message:@"是否前去完善实名认证信息？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//        alertView.tag = 14;
//        [alertView show];
//        return;
//    }
    
    TransferredViewController *transfer = [[TransferredViewController alloc] initWithNibName:@"TransferredViewController" bundle:nil];
    transfer.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:transfer animated:YES];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag==7 && buttonIndex==1) {
        //去实名认证
        AddBankCardViewController *addBankCard = [[AddBankCardViewController alloc] init];
        addBankCard.editType = 1;
        [self.navigationController pushViewController:addBankCard animated:YES];
    }else if (alertView.tag==14 && buttonIndex==1) {
        //去绑卡
        AddBankCardViewController *addBankCard = [[AddBankCardViewController alloc] init];
        addBankCard.editType = 1;
        [self.navigationController pushViewController:addBankCard animated:YES];
    }
}

- (IBAction)checkMoreDetailTap:(id)sender {
    
    [_scrollView setContentOffset:CGPointMake(0, MSHIGHT) animated:YES];
}

- (void)headerButtonClick:(UIButton *)button {
    if (button == _productDetailButton) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect frame = _buttonLineView.frame;
            frame.origin.x = 0;
            _buttonLineView.frame = frame;
            _detailScrollView.contentOffset = CGPointMake(0, 0);
        } completion:^(BOOL finished) {
            [self buttonChange:button];
        }];
    }else if(button == _propertyDirectionButton){
        [UIView animateWithDuration:0.3 animations:^{
            CGRect frame = _buttonLineView.frame;
            frame.origin.x = MSWIDTH/kButtonNum;
            _buttonLineView.frame = frame;
            _detailScrollView.contentOffset = CGPointMake(MSWIDTH, 0);
        } completion:^(BOOL finished) {
            [self buttonChange:button];
        }];
    }else {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect frame = _buttonLineView.frame;
            frame.origin.x = (MSWIDTH/kButtonNum)*2;
            _buttonLineView.frame = frame;
            _detailScrollView.contentOffset = CGPointMake(MSWIDTH*2, 0);
        } completion:^(BOOL finished) {
            [self buttonChange:button];
        }];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == _detailScrollView) {
        double OriginX = scrollView.contentOffset.x;
        if (OriginX>=0 && OriginX<=MSWIDTH*2) {
            CGRect frame = _buttonLineView.frame;
            frame.origin.x = (OriginX/MSWIDTH)*(MSWIDTH/kButtonNum);
            _buttonLineView.frame = frame;
            
            if (OriginX <= MSWIDTH/2) {
                [self buttonChange:_productDetailButton];
            }else if (OriginX>MSWIDTH/2 && OriginX<MSWIDTH+MSWIDTH/2) {
                [self buttonChange:_propertyDirectionButton];
            }else {
                [self buttonChange:_securityWayButton];
            }
        }
    }else if (scrollView == _scrollView) {
        // 还原滚动视图的背景色
        self.scrollView.backgroundColor = [UIColor whiteColor];
        if (scrollView.contentOffset.y < MSHIGHT/2) {
            
            [self initNavBarTitle:@"随取宝" andLeftItemName:@"返回" andRightItemName:@"项目详情"];
            [self setNavBarBackgroundColor:[UIColor clearColor] andStatusBar:UIStatusBarStyleLightContent];
            _isTop = YES;
        }else {
            [self initNavBarTitle:@"随取宝" andLeftItemName:@"返回" andRightItemName:@""];
            [self setNavBarBackgroundColor:KColor andStatusBar:UIStatusBarStyleLightContent];
            _isTop = NO;
        }
    }
}

- (void)buttonChange:(UIButton *)button {
    if (button == _productDetailButton) {
        [_productDetailButton setTitleColor:KColor forState:UIControlStateNormal];
        _productDetailButton.titleLabel.font = KFontBoldSize(14.0);
        
        [_propertyDirectionButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        _propertyDirectionButton.titleLabel.font = KFontSize(14.0);
        [_securityWayButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        _securityWayButton.titleLabel.font = KFontSize(14.0);
    }else if (button == _propertyDirectionButton) {
        [_productDetailButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        _productDetailButton.titleLabel.font = KFontSize(14.0);
        
        [_propertyDirectionButton setTitleColor:KColor forState:UIControlStateNormal];
        _propertyDirectionButton.titleLabel.font = KFontBoldSize(14.0);
        [_securityWayButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        _securityWayButton.titleLabel.font = KFontSize(14.0);
    }else {
        [_productDetailButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        _productDetailButton.titleLabel.font = KFontSize(14.0);
        
        [_propertyDirectionButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        _propertyDirectionButton.titleLabel.font = KFontSize(14.0);
        [_securityWayButton setTitleColor:KColor forState:UIControlStateNormal];
        _securityWayButton.titleLabel.font = KFontBoldSize(14.0);
    }
}

#pragma mark - Data
- (void)initData {
    _isTop = YES;
    
    [self requestData];
}

- (void)requestData {
    if (_isLoading) {
        return;
    }
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:@"501" forKey:@"OPT"];
    [parameters setObject:@"" forKey:@"body"];
    if (AppDelegateInstance.userInfo) {
        [parameters setObject:AppDelegateInstance.userInfo.userId forKey:@"userId"];
    }
    
    if (_requestClient == nil) {
        _requestClient = [[NetWorkClient alloc] init];
        _requestClient.delegate = self;
    }
    [_requestClient requestGet:@"app/services" withParameters:parameters];
}

- (void)startRequest {
    _isLoading = YES;
}

- (void)httpResponseSuccess:(NetWorkClient *)client dataTask:(NSURLSessionDataTask *)task didSuccessWithObject:(id)obj {
    _isLoading = NO;

    NSDictionary *dics=(NSDictionary *)obj;
    DLOG(@"--%@",dics);
    NSString *errorStr=[NSString stringWithFormat:@"%@",[dics objectForKey:@"error"]];
    if ([errorStr isEqualToString:@"-1"]) {
        
        NSDictionary *dataDict = dics[@"bao"];
        
        NSString *rateStr = [NSString stringWithFormat:@"%.2f%%",[dataDict[@"apr"] floatValue]];
        _rateLabel.attributedText = [MyTools getNSMutableAttributedStringWithText:rateStr start:rateStr.length-1 end:rateStr.length textColor:[UIColor whiteColor] textFont:KFontSize(13)];
        _yesProfitLabel.text = [NSString stringWithFormat:@"%@",[CommonClass formatConversion:[[dataDict objectForKey:@"yesterdayInterest"] doubleValue] type:0]];
        _totalAmountLabel.text = [NSString stringWithFormat:@"%@",[CommonClass formatConversion:[[dataDict objectForKey:@"amount"] doubleValue] type:0]];
        _totalProfitLabel.text = [NSString stringWithFormat:@"%@",[CommonClass formatConversion:[[dataDict objectForKey:@"receiveInterest"] doubleValue] type:0]];
        
        NSMutableDictionary *productDetailDict = [NSMutableDictionary dictionary];
        [productDetailDict setObject:dataDict[@"apr"] forKey:@"apr"];
        [_productDetail setDataDict:productDetailDict];
        
    }else {
        [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",[dics objectForKey:@"msg"]]];
    }
}

- (void)httpResponseFailure:(NetWorkClient *)client dataTask:(NSURLSessionDataTask *)task didFailWithError:(NSError *)error {
    _isLoading = NO;
}

- (void) networkError {
    _isLoading = NO;

}

#pragma mark - View
- (void)initView {
    _scrollView = [UIScrollView scrollViewWithFrame:RECTMAKE(0, 0, MSWIDTH, MSHIGHT) delegate:self backgroundColor:KbackgroundColor superview:self.view];
    _scrollView.contentSize = CGSizeMake(0, MSHIGHT * 2);
    _scrollView.pagingEnabled = YES;
    _scrollView.bounces = NO;
    
    //
    [self loadBriefScrollViewWithSuperView:_scrollView];
    
    //
    [self loadDetailScrollView];
    
    
}

- (void)viewWillLayoutSubviews {
    _scrollView.frame = RECTMAKE(0, 0, MSWIDTH, MSHIGHT);
    _detailScrollView.frame = RECTMAKE(0, 0, MSWIDTH, MSHIGHT);
    _buttonView.frame = CGRectMake(0, MSHIGHT + 64, MSWIDTH, KAdaptNum(45));
    _detailScrollView.frame = RECTMAKE(0, GetMaxY(_buttonView), MSWIDTH, MSHIGHT - 64 - GetHeight(_buttonView));
}

- (void)loadDetailScrollView {
    CGFloat scrollOriginY = KAdaptNum(45);
    
    _buttonView = [UIView viewWithFrame:CGRectMake(0, MSHIGHT + 64, MSWIDTH, scrollOriginY) backgroundColor:[UIColor whiteColor] superview:_scrollView];
    
    _productDetailButton = [UIButton buttonWithFrame:CGRectMake(0, 0, MSWIDTH/3, scrollOriginY - 1) backgroundColor:nil title:@"产品详情" titleColor:KColor titleFont:14.0 target:self action:@selector(headerButtonClick:) superview:_buttonView];
    
    _propertyDirectionButton = [UIButton buttonWithFrame:CGRectMake(MSWIDTH/3, 0, MSWIDTH/3, GetHeight(_productDetailButton)) backgroundColor:nil title:@"资产流向" titleColor:KBlackColor titleFont:14.0 target:self action:@selector(headerButtonClick:) superview:_buttonView];
    
    _securityWayButton = [UIButton buttonWithFrame:CGRectMake(MSWIDTH/3*2, 0, MSWIDTH/3, GetHeight(_productDetailButton)) backgroundColor:nil title:@"保障方式" titleColor:KBlackColor titleFont:14.0 target:self action:@selector(headerButtonClick:) superview:_buttonView];
    
    UIView *buttonLine = [UIView viewWithFrame:CGRectMake(0, CGRectGetMaxY(_productDetailButton.frame), MSWIDTH, _buttonView.frame.size.height - CGRectGetMaxY(_productDetailButton.frame)) backgroundColor:KlayerBorder superview:_buttonView];
    
    _buttonLineView = [UIView viewWithFrame:CGRectMake(0, 0, MSWIDTH/3, buttonLine.frame.size.height) backgroundColor:KColor superview:buttonLine];
    
    _detailScrollView = [UIScrollView scrollViewWithFrame:RECTMAKE(0, GetMaxY(_buttonView), MSWIDTH, MSHIGHT - 64 - GetHeight(_buttonView)) delegate:self backgroundColor:KbackgroundColor superview:_scrollView];
    _detailScrollView.contentSize = CGSizeMake(MSWIDTH * 3, 0);
    _detailScrollView.pagingEnabled = YES;
    
    _productDetail = [[ProductDetailView alloc] initWithFrame:RECTMAKE(0, 0, MSWIDTH, GetHeight(_detailScrollView))];
    _productDetail.deleagate = self;
    [_detailScrollView addSubview:_productDetail];
    
    _briefView = [[InvestmentBriefView alloc] initWithFrame:RECTMAKE(MSWIDTH, 0, MSWIDTH, GetHeight(_detailScrollView)) type:4];
    _briefView.deleagate = self;
    [_detailScrollView addSubview:_briefView];
    
    _webView = [[CommonWebViewController alloc] init];
    _webView.view.frame = RECTMAKE(MSWIDTH*2, 0, MSWIDTH, GetHeight(_detailScrollView));
    _webView.requestUrl = [NSString stringWithFormat:@"%@%@",Baseurl,@"/app/safeguard"];
    
    [_detailScrollView addSubview:_webView.view];
    
}

- (void)loadBriefScrollViewWithSuperView:(UIScrollView *)scrollView {
//    UITableView *tableView = [UITableView tableViewWithFrmae:RECTMAKE(0, 0, MSWIDTH, MSHIGHT) backgroundColor:KbackgroundColor delegate:self dataSource:self tableViewStyle:UITableViewStylePlain separatorStyle:UITableViewCellSeparatorStyleNone superview:scrollView];
    
    _briefScrollView = [UIScrollView scrollViewWithFrame:RECTMAKE(0, 0, MSWIDTH, MSHIGHT) delegate:self backgroundColor:KbackgroundColor superview:scrollView];

    UIImageView *backImageView = [UIImageView imageViewWithFrame:RECTMAKE(0, 0, MSWIDTH, KAdaptNum(264)) imageFile:@"sqbdetail_back_one" superview:_briefScrollView];
    
    UIImageView *backImageView2 = [UIImageView imageViewWithFrame:RECTMAKE((GetWidth(backImageView) - KAdaptNum(183))/2, GetHeight(backImageView) - KAdaptNum(161), KAdaptNum(183), KAdaptNum(161)) imageFile:@"sqbdetail_back_two" superview:backImageView];

    
    UIImageView *backImageView3 = [UIImageView imageViewWithFrame:RECTMAKE(0, GetHeight(backImageView) - KAdaptNum(135) + KAdaptNum(20), MSWIDTH, KAdaptNum(135)) imageFile:@"sqbdetail_back_three" superview:backImageView];
    backImageView3.userInteractionEnabled = YES;
    
    
    UIImageView *backImageView4 = [UIImageView imageViewWithFrame:RECTMAKE((GetWidth(backImageView) - KAdaptNum(130))/2, GetMinY(backImageView2) + (GetHeight(backImageView2) - KAdaptNum(80))/2, KAdaptNum(130), KAdaptNum(80)) imageFile:@"sqbdetail_back_four" superview:backImageView];
    
    _rateLabel = [UILabel labelWithFrame:RECTMAKE(5, KAdaptNum(5), GetWidth(backImageView4) - 10, KAdaptNum(40)) text:@"0.00" textColor:[UIColor whiteColor] textFont:36 fitWidth:YES superview:backImageView4];
    _rateLabel.textAlignment = NSTextAlignmentCenter;
    _rateLabel.font = KFontBoldSize(36);
    
    UIImageView *rateImageView = [UIImageView imageViewWithFrame:RECTMAKE(GetMinX(_rateLabel) + KAdaptNum(15), GetMaxY(_rateLabel) + KAdaptNum(5), KAdaptNum(12), KAdaptNum(14)) imageFile:@"sqbdetail_rate" superview:backImageView4];
    
    UILabel *rateValue1 = [UILabel labelWithFrame:RECTMAKE(GetMaxX(rateImageView) + KAdaptNum(5), GetMinY(rateImageView), GetWidth(backImageView4) - GetMaxX(rateImageView) - KAdaptNum(10), GetHeight(rateImageView)) text:@"7日年化收益率" textColor:[UIColor whiteColor] textFont:10 fitWidth:NO superview:backImageView4];
    rateValue1.textAlignment = NSTextAlignmentLeft;
    
    CGFloat valueSize = 12.0f;
    CGFloat valueHeight = [MyTools getSizeOfString:@"昨日收益(元)" maxWidth:KAdaptNum(100) maxHeight:KAdaptNum(20) withFontSize:valueSize].height;
    
    UIView *amountView = [UIView viewWithFrame:RECTMAKE(0, GetMaxY(backImageView), MSWIDTH, KAdaptNum(175)) backgroundColor:[UIColor whiteColor] superview:_briefScrollView];
    
    UILabel *profitValue = [UILabel labelWithFrame:RECTMAKE(10, KAdaptNum(25), MSWIDTH - 20, valueHeight) text:@"昨日收益(元)" textColor:KColor textFont:12 fitWidth:NO superview:amountView];
    profitValue.textAlignment = NSTextAlignmentCenter;
    
    _yesProfitLabel = [UILabel labelWithFrame:RECTMAKE(10, GetMaxY(profitValue) + KAdaptNum(10), MSWIDTH - 20, KAdaptNum(30)) text:@"0.00" textColor:KColor textFont:30 fitWidth:NO superview:amountView];
    _yesProfitLabel.textAlignment = NSTextAlignmentCenter;
    
    UIView *sepLine1 = [UIView viewWithFrame:RECTMAKE(10, GetMaxY(_yesProfitLabel) + KAdaptNum(20), MSWIDTH - 20, kLineHeight) backgroundColor:KlayerBorder superview:amountView];
    
    UILabel *totalAmountValue = [UILabel labelWithFrame:RECTMAKE(5, GetMaxY(sepLine1) + KAdaptNum(20), MSWIDTH/2 - 10, valueHeight) text:@"随取宝总额(元)" textColor:KGrayColor textFont:valueSize fitWidth:NO superview:amountView];
    totalAmountValue.textAlignment = NSTextAlignmentCenter;
    
    _totalAmountLabel = [UILabel labelWithFrame:RECTMAKE(GetMinX(totalAmountValue), GetMaxY(totalAmountValue) + KAdaptNum(10), GetWidth(totalAmountValue), KAdaptNum(20)) text:@"0.00" textColor:KBlackColor textFont:15 fitWidth:NO superview:amountView];
    _totalAmountLabel.textAlignment = NSTextAlignmentCenter;
    
    [UIView viewWithFrame:RECTMAKE(MSWIDTH/2, GetMaxY(sepLine1) + KAdaptNum(20), kLineHeight, KAdaptNum(40)) backgroundColor:KlayerBorder superview:amountView];
    
    UILabel *totalProfitValue = [UILabel labelWithFrame:RECTMAKE(MSWIDTH/2 + 5, GetMaxY(sepLine1) + KAdaptNum(20), MSWIDTH/2 - 10, valueHeight) text:@"累计收益(元)" textColor:KGrayColor textFont:valueSize fitWidth:NO superview:amountView];
    totalProfitValue.textAlignment = NSTextAlignmentCenter;
    
    _totalProfitLabel = [UILabel labelWithFrame:RECTMAKE(GetMinX(totalProfitValue), GetMaxY(totalProfitValue) + KAdaptNum(10), GetWidth(totalProfitValue), KAdaptNum(20)) text:@"0.00" textColor:KBlackColor textFont:15 fitWidth:NO superview:amountView];
    _totalProfitLabel.textAlignment = NSTextAlignmentCenter;
    
    _transOutButton = [[ClickButton alloc] initWithFrame:RECTMAKE(10, GetMaxY(amountView) + KAdaptNum(28), (MSWIDTH - 40)/2, KAdaptNum(40))];
    _transOutButton.layer.cornerRadius = kCornerRadius;
    [_transOutButton setTitle:@"转出" forState:UIControlStateNormal];
    [_transOutButton setBackColor:[UIColor clearColor] HighlightColor:[UIColor clearColor]];
    [_transOutButton setTitleColor:KColor forState:UIControlStateNormal];
    _transOutButton.layer.borderColor = KColor.CGColor;
    _transOutButton.layer.borderWidth = kLineHeight;
    [_transOutButton addTarget:self action:@selector(transOutButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_briefScrollView addSubview:_transOutButton];
    
    _transInButton = [[ClickButton alloc] initWithFrame:RECTMAKE(GetMaxX(_transOutButton) + 20, GetMinY(_transOutButton), GetWidth(_transOutButton), GetHeight(_transOutButton))];
    [_transInButton setTitle:@"转入" forState:UIControlStateNormal];
    [_transInButton addTarget:self action:@selector(transInButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_briefScrollView addSubview:_transInButton];
    
    if (GetMaxY(_transOutButton)+KAdaptNum(20) > GetHeight(_briefScrollView)) {
        _checkDetailView.frame = RECTMAKE(0, GetMaxY(_transOutButton) + KAdaptNum(20), MSWIDTH, KAdaptNum(45));
    }else {
        _checkDetailView.frame = RECTMAKE(0, GetHeight(_briefScrollView) - KAdaptNum(45), MSWIDTH, KAdaptNum(45));
    }
    
    [_briefScrollView addSubview:_checkDetailView];
    
    _briefScrollView.contentSize = CGSizeMake(0, GetMaxY(_checkDetailView));
    
}

#pragma mark - TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    if (self.view.frame.size.height > 420+45) {
//        return 1;
//    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = KbackgroundColor;
    }
    
    cell.frame=CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, self.view.frame.size.height - 420 - 45);
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
}

- (void)rightBarButtonClick {
//    CommonWebViewController *advantage = [[CommonWebViewController alloc] init];
//    advantage.naviTitle = @"随取宝优势";
//    advantage.typeStr = @"CheckAdvantage";
//    advantage.requestUrl = [NSString stringWithFormat:@"%@%@",Baseurl,@"/app/feature"];
//    CheckAdvantageViewController *advantage = [[CheckAdvantageViewController alloc] init];
    ProductDetailViewController *pdVC = [[ProductDetailViewController alloc] init];
    [self.navigationController pushViewController:pdVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
